<!DOCTYPE HTML>

<!-- READ BEFORE UPDATING:
If this test is updated make sure to increment the "revision" value of the
associated test in content/test/gpu/gpu_tests/pixel_test_pages.py. This will ensure
that the baseline images are regenerated on the next run.
-->

<html>
<head>
<title>OffscreenCanvas transferToImageBitmap on main thread: green and blue squares on white background.</title>
<style type="text/css">
.nomargin {
  margin: 0px auto;
}
</style>
<script>
var g_swapsBeforeAck = 15;

function main()
{
  draw();
  waitForFinish();
}

function draw()
{
  var width = 100;
  var height = 100;
  var aCanvas = new OffscreenCanvas(width, height);
  var gl = aCanvas.getContext('webgl');
  gl.clearColor(0.0, 1.0, 0.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);
  var image1 = aCanvas.transferToImageBitmap();
  gl.clearColor(0.0, 0.0, 1.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);
  var image2 = aCanvas.transferToImageBitmap();

  var canvas1 = document.getElementById("canvas1");
  var ctx1 = canvas1.getContext('bitmaprenderer');
  ctx1.transferFromImageBitmap(image1);

  var canvas2 = document.getElementById('canvas2');
  var ctx2 = canvas2.getContext('bitmaprenderer');
  ctx2.transferFromImageBitmap(image2);
}

function waitForFinish()
{
  if (g_swapsBeforeAck == 0) {
    domAutomationController.send("SUCCESS");
  } else {
    g_swapsBeforeAck--;
    document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1;
    window.requestAnimationFrame(waitForFinish);
  }
}
</script>
</head>
<body onload="main()">
<div style="position:relative; width:200px; height:200px; background-color:white">
</div>
<div id="container" style="position:absolute; top:0px; left:0px">
<canvas id="canvas1" width="100" height="100" class="nomargin"></canvas>
</div>
<div id="container" style="position:absolute; top:0px; left:150px">
<canvas id="canvas2" width="100" height="100" class="nomargin"></canvas>
</div>
</body>
</html>
